#include"TimeLebfthMemoryPool.H"
//#include"Common.h"
#include"ConcurrentAlloc.h"
#include"ThreadCache.h"
#include"PagaCache.h"

//void thread1()
//{
//	for (int i = 0; i < 5; i++){
//		void* ptr=ConcurrentAlloc(5);
//	}
//}
//
//void thread2()
//{
//	for (int i = 0; i < 5; i++){
//		void* ptr=ConcurrentAlloc(7);
//	}
//}
//
//void text()
//{
//	std::thread t1(thread1);
//	std::thread t2(thread2);
//	t1.join();
//	t2.join();
//}

void TestConcurrentAlloc1()
{
	void* p1 = ConcurrentAlloc(1);
	cout << p1 << endl;
	void* p2 = ConcurrentAlloc(5);
	cout << p2 << endl;
	void* p3 = ConcurrentAlloc(1);
	cout << p3 << endl;
	/*void* p4 = ConcurrentAlloc(8);
	cout << p4 << endl;
	void* p5 = ConcurrentAlloc(1);
	cout << p5 << endl;*/

	ConcurrentFree(p1);
	cout << "p1 " << endl;
	ConcurrentFree(p2);
	cout << "p2 " << endl;
	ConcurrentFree(p3);
	cout << "p3 " << endl;
	/*ConcurrentFree(p4, 8);
	cout << "p4 " << endl;
	ConcurrentFree(p5, 1);
	cout << "p5 " << endl;*/
}

void BigAlloc()
{
	void* p1 = ConcurrentAlloc(257 * 1024);
	ConcurrentFree(p1);

	void* p2 = ConcurrentAlloc(129 * 8 * 1024);
	ConcurrentFree(p2);
}

void TestConcurrentAlloc2()
{
	std::vector<void*> v;
	size_t begin1 = clock();
	for (size_t i = 0; i < 100000; ++i)
	{
		void* p1 = ConcurrentAlloc(16);
		v.push_back(p1);
	}
	
	for (size_t i = 0; i < 100000; ++i)
	{
		ConcurrentFree(v[i]);
	}
	size_t end1 = clock();
	cout << end1-begin1 << endl;
}

//int main()
//{
//	std::thread t1(TestConcurrentAlloc2);
//	//std::thread t2(TestConcurrentAlloc2);
//	//std::thread t3(TestConcurrentAlloc2);
//	//std::thread t4(TestConcurrentAlloc2);
//	t1.join();
//	/*t2.join();
//	t3.join();
//	t4.join();*/
//
//	
//	return 0;
//}